<style scoped lang="scss">
@import url('index.scss');
</style>
<template>
  <div class="app-container">
    <!--新模版样式-->
    <div class="topsearch">
      <el-row>
        <el-col :span="22" class="searchcol">
          <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="88px">
            <el-form-item label="科室ID" prop="kid">
              <el-select v-model="queryParams.kid" placeholder="请选择科室" clearable style="min-width: 205px;">
                <el-option v-for="item in departmentList" :key="item.kid" :label="item.kname" :value="item.kid" />
              </el-select>
            </el-form-item>
            <el-form-item label="诊室名称" prop="roomname">
              <el-input v-model="queryParams.roomname" placeholder="请输入诊室名称" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="诊室编号" prop="roomnumber">
              <el-input v-model="queryParams.roomnumber" placeholder="请输入诊室编号" clearable @keyup.enter="handleQuery" />
            </el-form-item>

            <el-form-item label="可预约时段" prop="timeSlice">
              <el-input v-model="queryParams.timeSlice" placeholder="请输入可预约时段" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="辐射分区" prop="radiationarea">
              <el-input v-model="queryParams.radiationarea" placeholder="请输入辐射分区" clearable
                @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="防护级别" prop="protectionlevel">
              <el-input v-model="queryParams.protectionlevel" placeholder="请输入防护级别" clearable
                @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="检查项目" prop="checkitems">
              <el-input v-model="queryParams.checkitems" placeholder="请输入检查项目" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="状态" prop="status">
              <el-input v-model="queryParams.status" placeholder="请输入状态" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item>
              <el-button class="newButton" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="22" class="rightcol">
          <div class="newbtn" @click="handleAdd" v-hasPermi="['system:consultingroom:add']">
            <img src="@/assets/images/add.svg" alt="">
            <span>新建</span>
          </div>
          <div class="newbtn" v-if="single == false" @click="handleUpdate" v-hasPermi="['system:consultingroom:edit']">
            <img src="@/assets/images/edit.svg" alt=""></img>
            <span>编辑</span>
          </div>
          <div class="newbtn" v-if="multiple == false" @click="handleDelete"
            v-hasPermi="['system:consultingroom:remove']">
            <img src="@/assets/images/del.svg" alt=""></img>
            <span>删除</span>
          </div>
          <div class="newbtn" @click="handleExport" v-hasPermi="['system:consultingroom:export']">
            <img src="@/assets/images/export.svg" alt=""></img>
            <span>导出</span>
          </div>
          <div class="newbtn" @click="getList">
            <img src="@/assets/images/refresh.svg" alt=""></img>
            <span>刷新</span>
          </div>
        </el-col>
      </el-row>
    </div>

    <div class="newtable">
      <el-table v-loading="loading" :data="consultingroomList" @selection-change="handleSelectionChange"
        :cell-style="{ backgroundColor: '#f9f9f9' }">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column type="expand" width="55" label="展开">
          <template #default="props">
            <div class="detail">
              <p>{{ props.row.remark }}</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="诊室ID" width="65" align="center" prop="cid" />
        <el-table-column label="科室ID" align="center" prop="kid">
          <template #default="scope">
            {{ departmentList.find(item => item.kid == scope.row.kid)?.kname || '-' }}
          </template>
        </el-table-column>
        <el-table-column label="诊室名称" align="center" prop="roomname" />
        <el-table-column label="诊室编号" align="center" prop="roomnumber" />
        <el-table-column label="诊室类型" align="center" prop="roomType">
          <template #default="scope">
            {{ ha_room_type.find(item => item.value == scope.row.roomType)?.label || '-' }}
          </template>
        </el-table-column>
        <el-table-column label="服务类型" align="center" prop="serviceType">
          <template #default="scope">
            {{ ha_roomservice_type.find(item => item.value == scope.row.serviceType)?.label || '-' }}
          </template>
        </el-table-column>
        <el-table-column label="候诊座位数" align="center" prop="seatNum" />
        <el-table-column label="可预约时段" align="center" prop="timeSlice" />
        <el-table-column label="辐射分区" align="center" prop="radiationarea">
          <template #default="scope">
            {{ ha_radiation_area.find(item => item.value == scope.row.radiationarea)?.label || '-' }}
          </template>
        </el-table-column>
        <el-table-column label="防护级别" align="center" prop="protectionlevel">
          <template #default="scope">
            {{ ha_protection_level.find(item => item.value == scope.row.protectionlevel)?.label || '-' }}
          </template>
        </el-table-column>
        <el-table-column label="检查项目" align="center" prop="checkitems" />
        <el-table-column label="叫号屏幕" align="center" prop="ledScreenId" />
        <el-table-column label="诊室状态" align="center" prop="status">
          <template #default="scope">
            <!-- {{ ha_normal_status.find(item => item.value == scope.row.status)?.label || '-' }} -->
             <el-tag :type="scope.row.status == '1' ? 'success' : 'danger'">{{ scope.row.status == '1' ? '正常' : '停用'
              }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="排序" align="center" prop="weigh" />
        <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
              v-hasPermi="['system:consultingroom:edit']">修改</el-button>
            <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
              v-hasPermi="['system:consultingroom:remove']">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize" @pagination="getList" />
    </div>




    <!-- 添加或修改诊室列表对话框 -->
    <el-dialog :title="title" v-model="open" width="50%" class="newDialog">
      <el-form ref="consultingroomRef" :model="form" :rules="rules" label-width="100px">

        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="所属科室" prop="kid">
              <!-- <el-input v-model="form.deptcode" placeholder="请选择科室" /> -->
              <el-select v-model="form.kid" placeholder="请选择科室" clearable>
                <el-option v-for="item in departmentList" :key="item.kid" :label="item.kname" :value="item.kid" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="诊室名称" prop="roomname">
              <el-input v-model="form.roomname" placeholder="请输入诊室名称" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="诊室编号" prop="roomnumber">
              <el-input v-model="form.roomnumber" placeholder="请输入诊室编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="候诊座位数" prop="seatNum">
              <el-input v-model="form.seatNum" placeholder="请输入候诊座位数" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="可预约时段" prop="timeSlice">
          <el-input v-model="form.timeSlice" placeholder="请输入可预约时段" />
        </el-form-item>
        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="诊室类型" prop="roomType">
              <!-- <el-input v-model="form.roomType" placeholder="请输入诊室类型" /> -->
              <el-select v-model="form.roomType" placeholder="请选择诊室类型" clearable>
                <el-option v-for="item in ha_room_type" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="服务类型" prop="serviceType">
              <!-- <el-input v-model="form.serviceType" placeholder="请输入服务类型" /> -->
              <el-select v-model="form.serviceType" placeholder="请选择服务类型" clearable>
                <el-option v-for="item in ha_roomservice_type" :key="item.value" :label="item.label"
                  :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="辐射分区" prop="radiationarea">
              <!-- <el-input v-model="form.radiationarea" placeholder="请输入辐射分区" /> -->
              <el-select v-model="form.radiationarea" placeholder="请选择辐射分区" clearable>
                <el-option v-for="item in ha_radiation_area" :key="item.value" :label="item.label"
                  :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="防护级别" prop="protectionlevel">
              <!-- <el-input v-model="form.protectionlevel" placeholder="请输入防护级别" /> -->
              <el-select v-model="form.protectionlevel" placeholder="请选择防护级别" clearable>
                <el-option v-for="item in ha_protection_level" :key="item.value" :label="item.label"
                  :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="检查项目" prop="checkitems">
          <el-input v-model="form.checkitems" placeholder="请输入可提供检查项目" />
        </el-form-item>

        <el-row :gutter="15">
          <el-col :span="12">
            <el-form-item label="叫号屏幕" prop="ledScreenId">
              <el-input v-model="form.ledScreenId" placeholder="请关联叫号屏幕" type="number" min="0" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="排序" prop="weigh">
              <el-input v-model="form.weigh" placeholder="请输入排序" type="number" min="0" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio v-for="dict in ha_normal_status" :key="dict.value" :value="dict.value" :label="dict.value">{{
              dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>

        <!-- <el-row :gutter="15">
          <el-col :span="12">

          </el-col>
          <el-col :span="12">

          </el-col>
        </el-row>

        <el-row :gutter="15">
          <el-col :span="12">

          </el-col>
          <el-col :span="12">

          </el-col>
        </el-row> -->

        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" type="textarea" rows="4" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Consultingroom">
import { listConsultingroom, getConsultingroom, delConsultingroom, addConsultingroom, updateConsultingroom } from "@/api/system/consultingroom"

import { listDepartment } from "@/api/system/department"

const { proxy } = getCurrentInstance()
const { ha_normal_status } = proxy.useDict('ha_normal_status'); // 使用字典
const { ha_protection_level } = proxy.useDict('ha_protection_level'); // 使用字典
const { ha_room_type } = proxy.useDict('ha_room_type'); // 使用字典
const { ha_roomservice_type } = proxy.useDict('ha_roomservice_type'); // 使用字典
const { ha_radiation_area } = proxy.useDict('ha_radiation_area'); // 使用字典


const consultingroomList = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    kid: null,
    roomname: null,
    roomnumber: null,
    roomType: null,
    serviceType: null,
    seatNum: null,
    timeSlice: null,
    radiationarea: null,
    protectionlevel: null,
    checkitems: null,
    ledScreenId: null,
    status: null,
    weigh: null,
  },
  rules: {
    kid: [
      { required: true, message: '请选择科室', trigger: 'blur' }
    ],
    roomname: [
      { required: true, message: '请输入诊室名称', trigger: 'blur' }
    ],
    roomnumber: [
      { required: true, message: '请输入诊室编号', trigger: 'blur' }
    ],
    roomType: [
      { required: true, message: '请选择诊室类型', trigger: 'blur' }
    ],
    serviceType: [
      { required: true, message: '请选择服务类型', trigger: 'blur' }
    ],

  }
})

const { queryParams, form, rules } = toRefs(data)

// 获取科室列表
const departmentList = ref([])

onMounted(() => {
   getDepartmentList()
})
const newQuery = {
  pageNum: 1,
  pageSize: 1000,
}
// 获取科室列表@鲍小伟20251111
function getDepartmentList() {
  listDepartment(newQuery).then(response => {
    console.log(response)
    if(response.code == 200){
      departmentList.value = response.rows
    } else {
      departmentList.value = []
    }
  })
}

/** 查询诊室列表列表 */
function getList() {
  loading.value = true
  listConsultingroom(queryParams.value).then(response => {
    consultingroomList.value = response.rows
    total.value = response.total
    loading.value = false
  })
}

// 取消按钮
function cancel() {
  open.value = false
  reset()
}

// 表单重置
function reset() {
  form.value = {
    cid: null,
    kid: null,
    roomname: null,
    roomnumber: null,
    roomType: null,
    serviceType: null,
    seatNum: null,
    timeSlice: null,
    radiationarea: null,
    protectionlevel: null,
    checkitems: null,
    ledScreenId: null,
    status: '1',
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    weigh: null,
    remark: null
  }
  proxy.resetForm("consultingroomRef")
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.cid)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd() {
  reset()
  open.value = true
  title.value = "添加诊室列表"
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset()
  const _cid = row.cid || ids.value
  getConsultingroom(_cid).then(response => {
    form.value = response.data
    open.value = true
    title.value = "修改诊室列表"
  })
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["consultingroomRef"].validate(valid => {
    if (valid) {
      if (form.value.cid != null) {
        updateConsultingroom(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
      } else {
        addConsultingroom(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
      }
    }
  })
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _cids = row.cid || ids.value
  proxy.$modal.confirm('是否确认删除诊室列表编号为"' + _cids + '"的数据项？').then(function() {
    return delConsultingroom(_cids)
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("删除成功")
  }).catch(() => {})
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('system/consultingroom/export', {
    ...queryParams.value
  }, `consultingroom_${new Date().getTime()}.xlsx`)
}

getList()
</script>
